package bm25;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class utils {
    public static List<String> getTopics(String topicPath){
        File file = new File(topicPath);
        Long fileLength = file.length();
        byte[] content = new byte[fileLength.intValue()];
        try{
            FileInputStream inputStream = new FileInputStream(file);
            inputStream.read(content);
            inputStream.close();
            //将content转换为String list
            String str = new String(content);
            List<String> res = new ArrayList<>();
            String[] temp = str.split("\n");
            for (String t : temp){
                String discription = t.split("\t")[1];
                res.add(discription.substring(1, discription.length() - 1));
            }
            return res;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
